package com.massa.caronafacil.db;

import java.sql.Connection;
import java.sql.DriverManager;

import android.util.Log;

public class SQLConnector {

	private final String driver = "com.mysql.jdbc.Driver";
	private final String username = "a7412290_massa";
	private final String password = "LuIzF0X";
	private final String port = "3306";
	private final String dbName = "a7412290_carona";
	private final String host = "mysql16.000webhost.com";
	private Connection conn = null;
	private String connString;
	private static SQLConnector instance;

    private SQLConnector() {
    	startConnection();
    }

    public static SQLConnector getInstance() {
        if ( SQLConnector.instance == null ) {
        	SQLConnector.instance = new SQLConnector();
        }
        return SQLConnector.instance;
    }

	private void startConnection() {
		try {
			Class.forName(driver).newInstance();
			connString = "jdbc:mysql://"+host+":"+port+"/"+dbName;
			conn = DriverManager.getConnection(connString, username, password);

			Log.w("Connection","open");
		} catch (Exception e) {
			Log.w("Connection","error " + e.getMessage());
		}
	}

	public Connection getConn() {
		return conn;
	}
}
